package com.scm.servlet.pomain;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.scm.page.Page;
import com.scm.model.Pomain;
import com.scm.service.PomainService;

/**
 * Servlet implementation class ShowEndPomainServlet
 */
@WebServlet("/main/pomain/ShowEndPomain")
public class ShowEndPomainServlet extends HttpServlet {
	private static final long serialVersionUID = 1756830184541573017L;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String payType = req.getParameter("payType");
		String status = req.getParameter("status");
		String currentpagestr = req.getParameter("currentPage");
		int currentpage = 1;
		if(currentpagestr != null && currentpagestr.matches("\\d++")) {
			currentpage = Integer.parseInt(currentpagestr);
		}
		Map<String,String> querymap = new HashMap<String,String>();
		querymap.put("payType", payType);
		querymap.put("status", status);
		try {
			
			Page<Pomain> page = new PomainService().selectPage(currentpage, querymap);
			String json = JSONArray.toJSONString(page);
			PrintWriter pw = resp.getWriter();
			pw.print(json);
			pw.flush();
			pw.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
